package com.hualan.sfzy.service.counselor.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.CounselorSkill;
import com.hualan.sfzy.mapper.counselor.CounselorSkillMapper;
import com.hualan.sfzy.service.counselor.CounselorSkillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CounselorSkillServiceImpl implements CounselorSkillService {
    @Autowired
    private CounselorSkillMapper mapper;


    @Override
    public int add(CounselorSkill entity) {
        return mapper.insert(entity);
    }

    @Override
    public int edit(CounselorSkill entity) {
        return mapper.update( entity);
    }

    @Override
    public int remove(Integer id) {
        return mapper.delete( id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return mapper.deleteBatch( ids);
    }

    @Override
    public List<CounselorSkill> find() {
        return mapper.select( null);
    }

    @Override
    public Map<String, Object> findPage(Integer pageNum, Integer pageSize, CounselorSkill entity) {
        //分页业务
        PageHelper.startPage(pageNum, pageSize);
        List<CounselorSkill> list = mapper.select(entity);
        PageInfo<CounselorSkill> pageInfo = new PageInfo<>(list);
//1.当前页面数据（数据列表）2.此次查询的总记录数
        Map<String, Object> pageMap = new HashMap<>();
        pageMap.put(CommonConstant.PAGE_LIST, list);
        pageMap.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        pageMap.put(CommonConstant.TOTAL, pageInfo.getTotal());
        return pageMap;
    }

    @Override
    public CounselorSkill findById(Integer id) {
        return mapper.selectById( id);
    }
}